import React from "react";
import { useRoutes, Navigate } from "react-router-dom";
import { lazyload } from "./utils/toolkit";
import { RouteObject } from "./types";
import common from "./modules/common";
import life from "./modules/life";
import test from "./modules/test";

// * 动态加载模块 https://cn.vitejs.dev/guide/features.html#json

const routes: RouteObject[] = [
  {
    path: "/",
    meta: {
      hidden: true,
    },
    element: <Navigate to={"/dashboard"} />,
  },
  {
    path: "/login",
    meta: {
      hidden: true,
    },
    element: lazyload(React.lazy(() => import("@/views/login/index"))),
  },
  ...common,
  ...life,
  ...test,
  {
    path: "*",
    meta: {
      hidden: true,
    },
    element: <Navigate to={"/"} replace={true}></Navigate>,
  },
];

export default () => useRoutes(routes);
